package com.twu.exercise;

public class Diamond {
    private String separator = System.getProperty("line.separator");

    public String print(int number) {
        String whiteSpace;
        String asterisk;
        StringBuilder result = new StringBuilder();

        for (int index = 0; index < 2 * number - 1; index++) {
            whiteSpace = printWhiteSpace(number, index);
            asterisk = printAsterisk(number, index);
            result.append(whiteSpace);
            result.append(asterisk);
            result.append(separator);
        }
        return result.toString();
    }

    private String printWhiteSpace(int number, int index) {
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < Math.abs(number - 1 - index); i++) {
            result = result.append(" ");
        }

        return result.toString();
    }

    private String printAsterisk(int number, int index) {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < 2 * number - 1 - 2 * Math.abs(number - 1 - index); i++) {
            result = result.append("*");
        }

        return result.toString();
    }
}
